//
//  DRSocialCommentCell.m
//  DoctorRen
//
//  Created by Lemon on 2018/11/29.
//

#import "DRSocialCommentCell.h"
#import <YYText/YYText.h>
#import <Masonry/Masonry.h>
@interface DRSocialCommentCell()

@property (nonatomic, strong) YYLabel *label;

@property (nonatomic, strong) UIImageView *iconIV;

@end

@implementation DRSocialCommentCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupSubViews];
    }
    return self;
}

-(void) setupSubViews{
    UIView * view = [UIView new];
    view.backgroundColor = UIColorFromHex(0xfafafa);
    [self addSubview: view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
    }];
    
    self.iconIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"评价"]];
    [view addSubview:self.iconIV];
    [self.iconIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.left.mas_equalTo(16);
    }];
    
    self.label = [[YYLabel alloc] init];
    self.label.numberOfLines = 0;
    self.label.font = [UIFont systemFontOfSize:13];
    self.label.textColor = UIColorFromHex(0x3B8B87);
    self.label.lineBreakMode = NSLineBreakByWordWrapping;
    [view addSubview:self.label];
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(48);
        make.right.mas_equalTo(-20);
        make.bottom.mas_equalTo(-10);
        make.top.mas_equalTo(10);
    }];
    
}

-(void)setComment:(NSDictionary *)dic isFirst:(BOOL)isFirst{
    self.iconIV.hidden = !isFirst;
    NSString *str = [NSString stringWithFormat:@"%@：%@",dic[@"user_name"],dic[@"content"]];
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str];
    [text yy_setColor:[UIColor lightGrayColor] range:[str rangeOfString:dic[@"content"]]];
    [text yy_setColor:UIColorFromHex(0x3B8B87) range:[str rangeOfString:dic[@"user_name"]]];
    self.label.attributedText = text;
}


@end
